package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoStorageCompanyListVO;
import com.yunxi.sto.pojo.StoStorageCompanyVO;
import com.yunxi.sto.service.StoStorageCompanyDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 仓储公司 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-06-06
 */
@RestController
@RequestMapping("/admin/stoStorageCompany")
@Api(tags = "sto:storageCompany", description = "仓储公司接口")
public class StoStorageCompanyController {
 private static final Logger logger = LoggerFactory.getLogger(StoStorageCompanyController.class);

 @Autowired
 StoStorageCompanyDubboService stoStorageCompanyDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(StoStorageCompanyVO stoStorageCompanyVO, Integer pageNum, Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoStorageCompanyDubboService.findPageByVO(stoStorageCompanyVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "storageCompanyId", value = "主键ID", required = true, dataType = "String")
 public ApiResult load(String storageCompanyId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoStorageCompanyDubboService.getById(storageCompanyId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoStorageCompanyVO stoStorageCompanyVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoStorageCompanyVO.setCreateBy(loginInfo.getUserCode());
  stoStorageCompanyVO.setUpdateBy(loginInfo.getUserCode());
  stoStorageCompanyDubboService.saveOrUpdate(stoStorageCompanyVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "停用")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoStorageCompanyDubboService.delAndReset(list,"0",loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "启用")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoStorageCompanyDubboService.delAndReset(list,"1",loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/companyList")
 @ApiOperation(value = "仓储公司列表")
 @ApiImplicitParam(paramType="query", name = "isOnUse", value = "是否启用(1是0否)", required = false, dataType = "String")
 public ApiResult companyList(String isOnUse) throws Exception {
  List<StoStorageCompanyListVO> list = stoStorageCompanyDubboService.companyList(isOnUse);
  return ResponseUtil.ok(list);
 }

 @GetMapping("/export")
 @ApiOperation(value = "导出查询")
 public ApiResult export(StoStorageCompanyVO stoStorageCompanyVO) throws Exception {
  return ResponseUtil.ok(stoStorageCompanyDubboService.export(stoStorageCompanyVO));
 }
}
